﻿using ApiIOCService.Interface;
using Microsoft.Practices.Unity;
using MyWeb.API.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
using System.Web.Mvc;
using TestCoupon.Model;

namespace TestApi.Controllers
{

    public class CouponController : ApiController
    {
        [Dependency]
        public ICouponService CouponService { get; set; }

        [System.Web.Http.HttpGet]
        public BaseResponseModel<CouponResponse> GetCouponBatch([FromUri]CouponRequest request)
        {
            BaseResponseModel<CouponResponse> result = new BaseResponseModel<CouponResponse>();
            try
            {
                request.Validate();
                var coupon = CouponService.GetCouponBatch(request.BatchId);
                if (coupon != null)
                {
                    CouponResponse data = new CouponResponse();
                    data.CouponBatch = coupon;
                    result = new SuccessResponseModel<CouponResponse>(data);
                }
                else
                {
                    result = new BussniessErrorResponseModel<CouponResponse>("数据不存在");
                }
            }
            catch (Exception ex)
            {
                result = new SystemErrorResponseModel<CouponResponse>(ex.Message);
            }
            return result;
        }

        [System.Web.Http.HttpPost]
        public BaseResponseModel<CouponListResponse> GetCouponBatchs([FromBody]CouponListRequest request)
        {
            BaseResponseModel<CouponListResponse> result = new BaseResponseModel<CouponListResponse>();
            try
            {
                var list = CouponService.GetCouponBatchs(request.BatchIds);
                if (list != null && list.Count > 0)
                {
                    CouponListResponse data = new CouponListResponse();
                    data.CouponBatchList = list;
                    result = new SuccessResponseModel<CouponListResponse>(data);
                }
                else
                {
                    result = new BussniessErrorResponseModel<CouponListResponse>("数据不存在");
                }
            }
            catch (Exception ex)
            {
                result = new SystemErrorResponseModel<CouponListResponse>(ex.Message);
            }
            return result;
        }
    }
}